﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace MuaBanLike.com
{
    public partial class MainWindow : Window
    {        
        BackgroundWorker thread = null;

        private void startLoginThread()
        {
            BackgroundWorker threadLogin = new BackgroundWorker();
            threadLogin.DoWork += delay1second;
            threadLogin.RunWorkerCompleted += startLogin;
            threadLogin.WorkerReportsProgress = true;
            threadLogin.WorkerSupportsCancellation = true;
            threadLogin.RunWorkerAsync();
        }

        private void startLogin(Object sender, RunWorkerCompletedEventArgs e)
        {
            if (!onLogin())
            {
                startLoginThread();
            }
        }

        void startCountTimeThread()
        {

            thread = new BackgroundWorker();
            thread.DoWork += delay20second;
            thread.RunWorkerCompleted += closePopupEndTime;
            thread.WorkerReportsProgress = true;
            thread.WorkerSupportsCancellation = true;
            thread.RunWorkerAsync();
        }

        private void delayTimeToNext()
        {
            startTime = DateTime.Now;
            thread = new BackgroundWorker();
            thread.DoWork += delay5second;
            thread.RunWorkerCompleted += finishToNext;
            thread.WorkerReportsProgress = true;
            thread.WorkerSupportsCancellation = true;
            thread.RunWorkerAsync();
        }

        private void finishToNext(Object sender, RunWorkerCompletedEventArgs e)
        {
            thread.CancelAsync();
            onLikeFakceBook();
        }

        private void closePopupEndTime(Object sender, RunWorkerCompletedEventArgs e)
        {          
            if (wnd != null)
            {
                wnd.disposeWebControl();
                wnd.Close();
                wnd = null;
            }
            startDetectStatusThread();
        }

    }
}
